<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />

    <title>Custom Recenter Widget | Sample | ArcGIS API for JavaScript 4.19</title>
    <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css" />

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        width: 100%;
        height: 100%;
      }

      .recenter-tool {
        padding: 2em;
        position: absolute;
        top: 1em;
        right: 1em;
        color: #fff;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
      }

      .recenter-tool>p {
        margin: 0;
      }
    </style>
    <script>
      const locationPath = location.pathname.replace(/\/[^\/]+$/, "");
      window.dojoConfig = {
        packages: [
          {
            name: "app",
            location: locationPath + "/app"
          }
        ]
      };
    </script>
    <script src="https://js.arcgis.com/4.19/"></script>
    <script>
      require(["esri/Map", "esri/Basemap", "esri/views/MapView", "app/Recenter", "esri/layers/VectorTileLayer"],(
        Map,
        Basemap,
        MapView,
        { default: Recenter },
        VectorTileLayer
      ) => {
        let map, view;
        const tileLayer = new VectorTileLayer({
          url:
            "https://www.arcgis.com/sharing/rest/content/items/92c551c9f07b4147846aae273e822714/resources/styles/root.json"
        });

        const basemap = new Basemap ({baseLayers: [ tileLayer ]});

        map = new Map({
          basemap: basemap
        });

        view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-100.33, 43.69],
          zoom: 4
        });
        view.when(() => {
          const recenter = new Recenter({
            view: view,
            initialCenter: [-100.33, 43.69]
          });
          view.ui.add(recenter, "top-right");
        });
      });
    </script>
  </head>
  <body>
    <div id="viewDiv" class="esri-widget"></div>
  </body>
</html>